﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MpSoft.Library.DAO.Contents;
using MpSoft.Library.DTO;
using MpSoft.Basic.Configuration;

namespace MpSoft.Library.BUSS.Contents
{

    #region  Gallery
    public class GalleryBUSS
    {
        private const string GALLERY_ALL_KEY = "Mp.gallery.all";
        private const string GALLERY_BY_ID_KEY = "Mp.gallery.id-{0}";
        private static void RemoveCache()
        {
            MpCache.RemoveByPattern(GALLERY_ALL_KEY);
            MpCache.RemoveByPattern(GALLERY_BY_ID_KEY);
        }
        public static int Gallery_Add(Gallery obj)
        {
            var result = GalleryDAO.Gallery_Add(obj);
            if (result > 0)
                RemoveCache();
            return result;
        }
        public static int Gallery_Update(Gallery obj)
        {
            var result = GalleryDAO.Gallery_Update(obj);
            if (result > 0)
                RemoveCache();
            return result;
        }

        public static int Gallery_Delete(int GalleryID)
        {
            var result = GalleryDAO.Gallery_Delete(GalleryID);
            if (result > 0)
                RemoveCache();
            return result;
        }

        public static Gallery Gallery_ByID(int GalleryID)
        {
            var list = Gallery_List(GalleryID, -1, int.MaxValue - 1, 0);
            if (list != null)
                return list.FirstOrDefault();
            return null;
        }
        public static List<Gallery> Gallery_ByCategory(int CategoryID)
        {
            return Gallery_ByCategory(CategoryID, int.MaxValue - 1);
        }

        public static List<Gallery> Gallery_ByCategory(int CategoryID, int RowNumber)
        {
            return Gallery_List(-1, CategoryID, RowNumber, 0);
        }

        public static List<Gallery> Gallery_List()
        {
            return Gallery_List(-1, -1, int.MaxValue - 1, 0);
        }
        public static List<Gallery> Gallery_List(int GalleryID, int CategoryID, int RowNumber, int IsActive)
        {
            return GalleryDAO.Gallery_List(GalleryID, CategoryID, RowNumber, IsActive);
        }
    }
    #endregion

}
